﻿@{
    ViewBag.Title = "bamM (BAM Website Version 2)";
    
}

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"
        type="text/javascript"></script>

<script type="text/javascript">

        $(document).ready(function () {
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetViewNames")',
                dataType: 'json',
                data: null,

                success: function (viewNames) {
                    // activities contains the JSON formatted list
                    // of states passed from the controller
                    $.each(viewNames, function (i, city) {
                        if (city.Text != null) {
                            $("#ddlviewNames").append('<option value="'
        + city.Value + '">'
        + city.Text + '</option>');
                        }
                    });
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
        });

        $(document).ready(function () {

            //Dropdownlist Selectedchange event
            $("#ddlviewNames").change(function () {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("GetActivities")',
                    dataType: 'json',
                    data: { id: $("#ddlviewNames option:selected").text() },

                    success: function (activities) {
                        // activities contains the JSON formatted list
                        // of states passed from the controller
                        $.each(activities, function (i, city) {
                            if (city.Text != null) {
                                $("#ddlActivities").append('<option value="'
        + city.Value + '">'
        + city.Text + '</option>');
                            }
                        });
                    },
                    error: function (ex) {
                        alert('Failed to retrieve states.' + ex);
                    }
                });
                return false;
            })
        });

        $(document).ready(function () {
            // this method has created for loading query filenames
            $("#ddlActivities").change(function () {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("GetQueryFileNames")',
                    dataType: 'json',
                    data: { viewName: $("#ddlviewNames option:selected").text(), activityName: $("#ddlActivities option:selected").text() },

                    success: function (queryFileNames) {
                        // activities contains the JSON formatted list
                        // of states passed from the controller
                        $.each(queryFileNames, function (i, city) {
                            if (city.Text != null) {
                                $("#ddlQueryFileNames").append('<option value="'
            + city.Value + '">'
            + city.Text + '</option>');
                            }
                        });
                    },
                    error: function (ex) {
                        alert('Failed to retrieve states.' + ex);
                    }
                });
            })
        });

        $(document).ready(function () {
            //Dropdownlist Selectedchange event
            $("#ddlQueryFileNames").change(function () {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("DisplayInstanceData")',
                    dataType: 'html',                    
                    data: { viewName: $("#ddlviewNames option:selected").text(), activityName: $("#ddlActivities option:selected").text(), queryName: $("#ddlQueryFileNames option:selected").text()  },
                });
                return false;
            })
        });

    $(document).ready(function () {

        $("#btnCustom").click(function (event) {
            event.preventDefault();

            var url = '@Url.Action("Index", "EditQuery")';
            alert(url);
            window.location.href = url;


        });
    });

</script>

<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <p class="lead"><h1><span class="glyphicon glyphicon-cloud">bamM</span> </h1><h4>(BAM Website Version 2)</h4> </p>
            </button>
            <p>
                View: @Html.DropDownList("viewNames", Enumerable.Empty<SelectListItem>(), "--Select One--", new { @id = "ddlviewNames" })
                Acitivity:@Html.DropDownList("Activities", Enumerable.Empty<SelectListItem>(), "--Select One--", new { @id = "ddlActivities" })
                Query:@Html.DropDownList("QueryFileNames", Enumerable.Empty<SelectListItem>(), "--Select One--", new { @id = "ddlQueryFileNames" })
                <input type="button" class="btn-default" id="btnCustom" value="Customize View" /> 
            </p>
        </div>
        <div>
            <p class="nav navbar-text navbar-right">Hello, @User.Identity.Name! </p>
        </div>

        


    </div>
</div>
    @using System.Collections
    @model IEnumerable
    @{
        var grid = new WebGrid((IEnumerable<dynamic>)Model, canPage: true, rowsPerPage: 50, ajaxUpdateContainerId: "gridContent");
    }
    @grid.GetHtml(tableStyle: "webGrid")
